---
# Configuration for the tahrir webapp


# TODO -- add the cronjob


- name: install needed packages
  package: name={{ item }} state=present
  with_items:
  - fedora-tagger
  - python-psycopg2
  - python-memcached
  - python-webob
  - koji
  tags:
  - packages
  - tagger

- name: link the README into the right place because tagger is ridiculous
  file: >
    src=/usr/lib/python2.7/site-packages/fedoratagger/README.rst
    dest=/usr/lib/python2.7/site-packages/README.rst
    state=link
  tags:
  - config
  - ridiculous
  - tagger

- name: make the cache directory
  file: >
    path=/var/cache/fedoratagger
    state=directory
    owner=apache group=apache mode=0755
  tags:
  - config
  - tagger

- name: copy tagger app configuration
  template: >
    src=fedoratagger.cfg.j2
    dest=/etc/fedoratagger/fedoratagger.cfg
    owner=apache
    group=apache
    mode=0640
  tags:
  - config
  - tagger
  notify:
  - restart apache

- name: copy tagger httpd config
  template: >
    src=fedoratagger-app.conf
    dest=/etc/httpd/conf.d/fedoratagger.conf
    owner=apache
    group=apache
    mode=0644
  tags:
  - config
  - tagger
  notify:
  - restart apache

- name: copy tagger alembic config
  template: >
    src=alembic.ini
    dest=/usr/share/fedoratagger/alembic.ini
    owner=apache
    group=apache
    mode=0640
  tags:
  - config
  - tagger

- name: Set some selinux booleans
  seboolean: name={{item}} persistent=yes state=yes
  with_items:
  - httpd_can_network_connect_db
  - httpd_verify_dns
  tags:
  - selinux
  - tagger

- name: check log file
  command: stat /var/log/fedoratagger.log
  register: logstat
  check_mode: no
  changed_when: "1 != 1"
  ignore_errors: true
  tags:
  - tagger

- name: ensure cronjob log file is writable
  file: >
    dest=/var/log/fedoratagger.log
    state=touch
    owner=apache group=apache mode=0755
  tags:
  - cron
  - config
  - tagger
  when: logstat.rc == 1

- name: setup the update-with-new-packages cronjob
  copy: >
    src=cron-tagger-update-db
    dest=/etc/cron.d/cron-tagger-update-db
  tags:
  - cron
  - config
  - tagger
  when: install_tagger_cron

- name: setup the remove-old-and-crusty-packages cronjob
  copy: >
    src=cron-tagger-remove-retired
    dest=/etc/cron.d/cron-tagger-remove-retired
  tags:
  - cron
  - config
  - tagger
  when: install_tagger_cron
